﻿;(function  ($) {
	
	var personalcenterObj = function  () {
		var signBtn;//签到按钮
		var processbar;//进度条
		var progerName;//进度条后面的文字
		var progreBeforeName;//进度条前面的文字
		var progressTips; //还差多少分可以升级
		var clickCount = 0;//点击次数
		var fullbar;
		var i=0;
		var level = 1;
		var loadEvent = function  () {
			signBtn.on("click",changeWHandler);
			fullbar.on("mouseover",showPoints);
			fullbar.on("mouseout",hidePoints);
		}

		var showPoints = function () {

			progressTips.html("还差"+(100-i)+"分可以升级");
			progressTips.show();
		}
		var hidePoints = function () {
			progressTips.hide();
		}
		
		var changeWHandler = function () {
//			i = i+10;
//
//			if(i==100){
//				level +=1;
//				i=0;
//				processbar.css("width",i+'%');
//				progerName.html("");
//				progerName.html(level+"星");
//				progreBeforeName.html(level-1+"星")
////				console.log("level="+":"+level);
////				console.log("i="+":"+i);
//			}else{
//				processbar.css("width",i+'%');
////				console.log("i="+":"+i);
//			}
////			console.log("i="+":"+i);//控制台打印输出i的值
//			i=i;
//			console.log("i="+":"+i);//控制台打印输出i的值
			  if (clickCount > 0) {
	           alert("今天已经签过到了，请明天再来");
	           return false;
		     }
		     	//按钮功能实现
		    	clickCount++; //点击统计累加

			$.ajax({
				type:"post",
				url:"personLevel",
				success:function  (i) {
					
					var star = parseInt(i)>=100?Math.floor(i/100)+1:1;
					
						processbar.css("width",(i-(star-1)*100)+'%');
						progerName.html("");
						progerName.html(star+1+"星");
						progreBeforeName.html(star+"星");
				
				}
			});
			
		}
		return{
			init:function  () {
				progressTips = $(".progress-tips");
				signBtn = $("#signbtn");
				progreBeforeName = $(".progre-name");
				processbar = $(".processbar");
				progerName = $(".proger-name");
				fullbar = $(".fullbar");
				
				loadEvent();

			}
		}
	}();
	personalcenterObj.init();
})(jQuery);
